Trò chơi đua xe động vật trong UNITY Engine
114.724 lượt xem;
1 using UnityEngine;
2 using System.Collections.Generic;
3
4 public class ActionParallel : Action {
5
6 protected List<Action> myActions = new List<Action>(0);
7 private bool complete;
8
9 public ActionParallel() { }
10 public ActionParallel(params Action[] actions) {
11 for (int i = 0; i < actions.Length; i++)
12 {
13 this.myActions.Add(actions[i]);
14 }
15 }
16
17 public override bool Act(float delta)
18 {
19 if (complete) return true;
20 complete = true;
21 try
22 {
23 for (int i = 0, n = myActions.Count; i < n && actor != null; i++)
24 {
25 if (!myActions[i].Act(delta)) complete = false;
26 if (actor == null) return true;
27 }
28 return complete;
29 }
30 finally { }
31 }
32
33 public void addAction(Action action)
34 {
35 myActions.Add(action);
36 if (actor != null) action.setActor(actor);
37 }
38
39 public override void setActor(Actor actor)
40 {
41 List<Action> actions = this.myActions;
42 for (int i = 0, n = myActions.Count; i < n; i++)
43 myActions[i].setActor(actor);
44 base.setActor(actor);
45 }
46
47 public override void restart()
48 {
49 complete = false;
50 List<Action> actions = this.myActions;
51 for (int i = 0, n = myActions.Count; i < n; i++)
52 myActions[i].restart();
53 }
54 }
2 using System.Collections.Generic;
3
4 public class ActionParallel : Action {
5
6 protected List<Action> myActions = new List<Action>(0);
7 private bool complete;
8
9 public ActionParallel() { }
10 public ActionParallel(params Action[] actions) {
11 for (int i = 0; i < actions.Length; i++)
12 {
13 this.myActions.Add(actions[i]);
14 }
15 }
16
17 public override bool Act(float delta)
18 {
19 if (complete) return true;
20 complete = true;
21 try
22 {
23 for (int i = 0, n = myActions.Count; i < n && actor != null; i++)
24 {
25 if (!myActions[i].Act(delta)) complete = false;
26 if (actor == null) return true;
27 }
28 return complete;
29 }
30 finally { }
31 }
32
33 public void addAction(Action action)
34 {
35 myActions.Add(action);
36 if (actor != null) action.setActor(actor);
37 }
38
39 public override void setActor(Actor actor)
40 {
41 List<Action> actions = this.myActions;
42 for (int i = 0, n = myActions.Count; i < n; i++)
43 myActions[i].setActor(actor);
44 base.setActor(actor);
45 }
46
47 public override void restart()
48 {
49 complete = false;
50 List<Action> actions = this.myActions;
51 for (int i = 0, n = myActions.Count; i < n; i++)
52 myActions[i].restart();
53 }
54 }